import {
  GetInstanceDeployStatusParams,
  IfDeployItem,
  PurchaseInstanceParams,
  SaaSPurchaseInstanceParams,
  saasPurInsParams,
  StrategyItem,
} from './model/purchaseModel';
import { deployHttp, jobHttp, tenantHttp } from '/@/utils/http/axios';

enum Api {
  saasPurIns = '/v1/database/initTenantDB',
  TENANT_PURCHASE_INSTANCE = '/v1/jobs/deployment/createTenantBusinessResources',
  SAAS_PURCHASE_INSTANCE = '/v1/deployment/initPackageInfo',
  INSTANCE_DEPLOY_JOB_STATUS = '/v1/job/status',
  GET_DEPLOY_STRATEGY = '/v1/deployment/strategies',
  GET_IF_DEPLOY = '/deployment/tenantConsoleDeploymentIsSuccess',
}

export const purchaseInstance = (params: SaaSPurchaseInstanceParams) => {
  return deployHttp.post<string>({ url: Api.SAAS_PURCHASE_INSTANCE, params });
};

export const createTenantBusinessResources = (params: PurchaseInstanceParams) => {
  params.packagePurchase.notificationEnabled = params.packagePurchase.isEnableNotification;
  const res = jobHttp.post<string>({ url: Api.TENANT_PURCHASE_INSTANCE, params });
  return res;
};

export const getInstanceDeployStatus = (params: GetInstanceDeployStatusParams) => {
  return deployHttp.get<string>({
    url: Api.INSTANCE_DEPLOY_JOB_STATUS,
    params,
  });
};
export const getDeployStrategy = () => {
  const result = deployHttp.get<StrategyItem[]>({
    url: Api.GET_DEPLOY_STRATEGY,
  });
  return result;
};

export const saasPurIns = (params: saasPurInsParams) => {
  return tenantHttp.get<string>({ url: Api.saasPurIns, params });
};

export const getIfDeploy = (param: string) => {
  const params = { userId: param };
  const res = tenantHttp.get<IfDeployItem>({
    url: Api.GET_IF_DEPLOY,
    params,
  });
  return res;
};
